// Listing 14.2 Using dynamic_cast.
// Using rtti
#include <iostream>
using namespace std;

enum TYPE { HORSE, PEGASUS };
class Horse {
public:
  virtual void Fly() { cout << "I can fly! I can fly! I can fly!"; }

private:
  int itsAge;
};

class Pegasus : public Horse {
public:
  virtual void Fly() { cout << "I can fly! I can fly! I canf fly!"; }
};

const int NumberHorse = 5;
int main(void) {
  Horse *Ranch[NumberHorse];
  Horse *pHorse;
  int choice, i;
  for (i = 0; i < NumberHorse; i++) {
    cout << "(1)Horse (2)Pegasus: ";
    cin >> choice;
    if (choice == 2) {
      pHorse = new Pegasus;
    } else {
      pHorse = new Horse;
    }
    Ranch[i] = pHorse;
  }
  cout << endl;
  for (i = 0; i < NumberHorse; i++) {
    Pegasus *pPeg = dynamic_cast<Pegasus *>(Ranch[i]);
    if (pPeg != nullptr) {
      pPeg->Fly();
    } else {
      cout << "Just a hourse\n";
    }
    delete Ranch[i];
  }
  return 0;
}